#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;

LL n, a[N];

int main()
{
	cin >> n;
	for(int i = 1;i <= n;i ++) cin >> a[i];
	LL ans = -1e5, s = -1e5;
	for(int i = 1;i <= n;i ++)
	{
		s = max(a[i], s + a[i]);
		ans = max(ans, s);
	}
	cout << ans << endl;
	return 0;
}